package com.gexiaobao.pigeon.app.util

import com.gexiaobao.pigeon.app.rxui.tablayout.listener.ActionCallback
import java.util.Date
import java.util.Timer
import kotlin.concurrent.schedule

/**
 * @Author      : hxw
 * @Date        : 2023/5/9 10:49
 * @Describe    :
 */
class CycleSender {

    private var timer: Timer = Timer()
    private var runningTag = false

    companion object {
        val INSTANCE by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
            CycleSender()
        }
    }

    //启动循环
    fun start(callback: ActionCallback<String, String>, period: Long) {
        if (!runningTag) {
            runningTag = true
            timer = Timer()
            timer.schedule(0, period * 1000) {
                callback.actionDo("TAG", "VALUE")
            }
        }
    }

    //暂停循环
    fun stop() {
        if (runningTag) {
            runningTag = false
            timer.cancel()
        }
    }
}